import { ProFormOptions, FormItemProps } from '@/components/pro-form/type'
import { GridItemProps } from 'naive-ui'
import { ReceiveModel } from '@/api/model/workflow/receive-model'
import { optionsType } from '~/types/form'
import { Ref } from 'vue'
import useGetReceiveAssetList from '@/hooks/useGetReceiveAssetList'
type Props = {
  handleType: Ref<'add' | 'edit' | 'check'>
  // typeOptions: Ref<any>
  // typeLoading: Ref<boolean>
  // budgetOptions: Ref<any>
  // budgetLoading: Ref<boolean>
}
export const useReceiveProForm = ({ handleType }: Props) => {
  const [receiveForm, resetReceiveForm] = useProRef<Partial<ReceiveModel>>({})

  const { typeOptions, typeLoading } = useGetTypeList()
  const { fetchGetReceiveList, receiveOptions, receiveLoading } =
    useGetReceiveAssetList()

  const receiveFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'receiveCode',
        label: '领用编码',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveBranch',
        label: '申请部门',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '领用人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'getBranch',
        label: '领用部门',
        disabled: true
      },
      {
        formType: 'date',
        key: 'receiveDate',
        label: '申请日期',
        disabled: true
      },
      {
        formType: 'input',
        key: 'getDate',
        label: '领用日期',
        noRule: true,
        disabled: true
      },
      {
        formType: 'select',
        key: 'receiveType',
        label: '领用状态',
        disabled: true,
        options: useDictData('STATUS').value
      },
      {
        formType: 'select',
        key: 'typeId',
        label: '资产类型',
        options: typeOptions.value,
        loading: typeLoading.value
      },
      {
        formType: 'textarea',
        key: 'receiveReason',
        label: '申请原因',
        rows: 1,
        gridItem: {
          span: 1
        },
        placeholder: '请输入申请原因',
        noRule: true
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        gridItem: {
          span: 2
        },
        placeholder: '请输入备注',
        noRule: true
      },
      {
        formType: 'select',
        key: 'assetCode',
        label: '分配资产',
        options: receiveOptions.value,
        loading: receiveLoading.value,
        noRule: true,
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'reason',
        label: '批复',
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: true
      }
    ] as optionsType
    return handleType.value === 'add'
      ? useSetOptions(list.filter((item) => !item.disabled))
      : useSetOptions(list)
  })

  return {
    receiveForm,
    receiveFormOptions,
    resetReceiveForm
  }
}
